<!DOCTYPE HTML>
<html>
<head>
	<title>我的个人博客</title>
	<meta charset="utf8">
	<link rel="stylesheet" type="text/css" href="style.css">
	<link rel="icon" type="image/png" href="simbs.png">
</head>
<body>

<div class="top">
	<div class="header"> 
		<div class="logo">
			<a href='index.php'><img src="logo.png"></a>
		</div>
		<div id="container">
			<ul>
<?php
	//调用配置文件config.php
	require_once 'config.php';
	//连接数据库 
	$conn = mysql_connect($host, $dbusername,$dbpassword);
	if(!$conn){
		die("连接失败".mysql_error());
	}
	//设置访问数据库的编码
	mysql_query("set names utf8",$conn) or die(mysql_errno());
	//选择数据库
	mysql_select_db($dbname,$conn) or die(mysql_errno());


	$sql = "select * from catalogs";
	$res = mysql_query($sql,$conn);
	while($row=mysql_fetch_assoc($res)){
		$cid = $row['cid'];
		echo "<li><a href=blogManage.php?list=$cid>{$row['catalog']}</a></li>";
	}
	mysql_free_result($res);
	mysql_close($conn);
?>
			</ul>
		</div>
	</div>
	<div class="single">
<?php
	//如果收到blogAdd.php传送的id,则显示那个id的文章

	//接受id
	if(!empty($_GET['id'])){
		$id=$_GET['id'];
	}
	//调用配置文件config.php
	require_once 'config.php';
	//连接数据库 
	$conn = mysql_connect($host, $dbusername,$dbpassword);
	if(!$conn){
		die("连接失败".mysql_error());
	}
	//设置访问数据库的编码
	mysql_query("set names utf8",$conn) or die(mysql_errno());
	//选择数据库
	mysql_select_db($dbname,$conn) or die(mysql_errno());


	//从数据库中取出id号的文章
	$sql = "select title,content from blog where id=$id ";
	$res = mysql_query($sql,$conn);
	$row = mysql_fetch_assoc($res);

	//打印id号的文章
	echo "<div id='title'><h2>{$row['title']}</h2></div>";
	echo "<div id='content'><p>{$row['content']}</p></div>";	

	//关闭资源和数据库
	mysql_free_result($res);
	mysql_close($conn);
?>
	</div>
	<div class="sidebar">
		<div class="loginSuccess">
			<?php
				session_start();
				if(!empty($_SESSION['name'])){
				echo "当前用户: ".$_SESSION['name']."<br />";
                                echo "<a href='blogList.php'>管理博文</a><br/>";
                                echo "<a href='blogAdd.php'>添加博文</a><br/>";
                                echo "<a href='configManage.php'>管理设置</a><br/>";
				echo "<a href='login.php'>重新登录</a>";
				} else{
				echo "<a href='login.php'>用户登录</a>";
				}
               		?>      
		</div>
		<div class="latest">最近更新
		<ul>
<?php
	//调用配置文件config.php
	require_once 'config.php';
	//连接数据库 
	$conn = mysql_connect($host, $dbusername,$dbpassword);
	if(!$conn){
		die("连接失败".mysql_error());
	}
	//设置访问数据库的编码
	mysql_query("set names utf8",$conn) or die(mysql_errno());
	//选择数据库
	mysql_select_db($dbname,$conn) or die(mysql_errno());



	//查询最新的10条记录
	$sql = "select title,id from blog order by time desc limit 0,10";
	$res = mysql_query($sql,$conn);

	//打印结果
	while($row=mysql_fetch_assoc($res)){
		$id = $row['id'];
		echo "<li><a href='blogPage.php?id=$id'>{$row['title']}</a></li>";
	}

	//关闭资源和数据库
	mysql_free_result($res);
	mysql_close($conn);
?>
		</ul>
		</div>
	</div>
	<div id="footer">
		<p>Copyright &#169;2012 Powered by <a href="http://code.google.com/p/simbs/">simbs</a> </p>
	</div>
</div>
</body>
</html>
